package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.entity.rank.stronghold.CrossActivityUnionRank;
import com.yanqu.road.logic.cross.stronghold.CrossActivityUnionRankModel;
import com.yanqu.road.logic.cross.stronghold.CrossStrongholdActivityRankListModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.manager.strongholdwar.CrossStrongholdRankMgr;

import java.util.List;
import java.util.Map;

public class StrongholdRank extends BaseCrossRank {
    public StrongholdRank(int activityId) {
        super(activityId);
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
        msg.setActivityId(activityId);
        List<CrossStrongholdActivityRankListModel> modelList = CrossStrongholdRankMgr.getCrossActivityRankListModel(activityId);
        for (CrossStrongholdActivityRankListModel rankListModel : modelList) {
            int conditionType = rankListModel.getConditionType();
            if (conditionType != eGamePlayerEventType.StrongholdWildScoreRank.getValue() && conditionType != eGamePlayerEventType.StrongholdEliminateRank.getValue()) {
                continue;
            }
            int rank = 0;
            for (CrossUserRank rankData : rankListModel.getRankList()) {
                long userId = rankData.getUserId();
                rank++;
                addUserRankData(msg, conditionType, userId, rank);
            }
        }
        return msg;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        AutoSendRewardProto.CrossUnionRankMsg.Builder msg = AutoSendRewardProto.CrossUnionRankMsg.newBuilder();
        msg.setActivityId(activityId);
        List<CrossActivityUnionRankModel> modelList = CrossStrongholdRankMgr.getCrossActivityUnionRankModelList(activityId);
        for (CrossActivityUnionRankModel rankListModel : modelList) {
            int conditionType = rankListModel.getConditionType();
            if (conditionType != eGamePlayerEventType.StrongholdWildUnionScoreRank.getValue() && conditionType != eGamePlayerEventType.StrongholdEliminateUnionRank.getValue()) {
                continue;
            }
            int rank = 0;
            for (CrossActivityUnionRank rankData : rankListModel.getRankList()) {
                String unionUid = rankData.getUnionUid();
                rank++;
                addUnionRankData(msg, conditionType, unionUid, rank);
            }
        }
        return msg;
    }
}
